package other;

import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

public class BasicTest {
    @Test
    public void testConcurrentException() {
        Map<String, String> map = new HashMap<>();
        map.put("key1", "value1");
        map.put("key2", "value2");
        map.put("key3", "value3");

        int length = map.size();
        for (int i = 0; i < length; i++) {
            if (i == 1) {
                map.remove("key3");
            }
            for (String key : map.keySet()) {
                System.out.println(key);
            }
        }
    }

    @Test
    public void testCAS() {
        new AtomicInteger().getAndIncrement();//源码分析
    }
}
